require(["jquery","bbcare",
        "scprit/department/vm/assessmentScreening/nbnaAssessment.ui.js",
        "scprit/department/vm/assessmentScreening/assessmentScreeningQuestion.servers.js",
        "scprit/department/vm/assessmentScreening/nbnaAssessment.event.js"],
    function ($,$bb,$ui,$servers,$event) {
        var getParams = $bb.getPageParams();
        var type = getParams.type;
        var userId = getParams.userId;
        var answerId = getParams.answerId;
        //问卷题目获取：
        var paramsQuestion = $servers.getParams(type,userId);
        //患者信息展示：
        var infoParams = $servers.infoParams(userId);
        var infoFn = function(dt){
            //基本信息渲染：
            dt= dt.data;
            var testDate = $servers.getNowFormatDate();
            if(answerId){testDate = getParams.testTime;}
            var diff = $servers.dateDiff(dt.PatientInfo.birthday,testDate);
            var monthAge = $servers.getMonthAge(diff,dt.PatientInfo.pregnancyDay);
            dt.PatientInfo = $.extend({}, dt.PatientInfo,monthAge);
            dt.PatientInfo.testDate = testDate;
            $ui.basicInfoInit({"id":"#basic-info","data":dt.PatientInfo});
           /* var quesFn = function(data){
            };
            $servers.getQuestion(paramsQuestion,quesFn);*/
            ajaxData();
        };
        $servers.getInfo(infoParams,infoFn);
        var ajaxData = function(){
            $bb.ajax({
                url: "scprit/department/data/nbna/nbna.json",
                success: function (data) {
                    if(data.success){
                        var scoreObj={};
                        if(answerId){
                            scoreObj = JSON.parse(getParams.answer.answerResult).map;
                            $event.countTotalScore(scoreObj);
                            $("#btn-submit").html("查看结果");
                        }
                        var itemArr = ["行为能力","被动肌张力","主动肌张力","原始反射","一般反应"];
                        data = data.data;
                        var tabs = $event.tabs(data,scoreObj);
                        $ui.tabsInit({"id":"#tabs","data":tabs});
                        $event.dataDeal(data,scoreObj);
                        $event.tabClick(data);
                        $event.quesClick(data);
                        if(!answerId){
                            $event.optionsClick(data,scoreObj,itemArr);
                        }
                        $('#tabs>li[class*="checked"]').click();
                        $event.submitBtn(scoreObj,type,userId,answerId);
                    }
                }
            });
        }
    });